// 定义 Vuex 模块（模块名称按照模块功能命名）
// const state = {};

// const getters = {};

// const actions = {};

// const mutations = {};

// export default {
//   state,
//   getters,
//   actions,
//   mutations,
// };

export default {
  // 开启命名空间（真正将所有数据隔离）
  namespaced: true,
  state: {
    count: 0,
  },
  getters: {
    oddOrEven(state) {
      return state.count % 2 === 1 ? "奇数" : "偶数";
    },
  },
  actions: {
    increment({ commit }, val) {
      console.log("counter increment");
      commit("INCREMENT", val);
    },
    decrement({ commit }, val) {
      commit("DECREMENT", val);
    },
    incrementIfOdd({ commit, state }, val) {
      if (state.count % 2 === 1) {
        commit("INCREMENT", val);
      }
    },
    incrementAsync({ commit }, val) {
      setTimeout(() => {
        commit("INCREMENT", val);
      }, 1000);
    },
  },
  mutations: {
    INCREMENT(state, val) {
      state.count += val;
    },
    DECREMENT(state, val) {
      state.count -= val;
    },
  },
};
